//
//  LXJTrackViewController.m
//  HMSport
//
//  Created by 李旭杰 on 2017/4/23.
//  Copyright © 2017年 LiXujie. All rights reserved.
//

#import "LXJTrackViewController.h"
#import "LXJMapViewController.h"

@interface LXJTrackViewController ()

/**
 地图
 */
@property (nonatomic, strong) LXJMapViewController *mapVc;


/**
总距离
 */
@property (weak, nonatomic) IBOutlet UILabel *totalDisdance;

/**
 总时长
 */
@property (weak, nonatomic) IBOutlet UILabel *totalTime;
@end

@implementation LXJTrackViewController

- (instancetype)init{
    if (self = [super init]) {
        [self setupMapView];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(locationDidUpdateNote) name:@"LXJSportLocationDidUpdateNote" object:nil];

}

//位置更新后响应
- (void)locationDidUpdateNote{
    
    //设置数据
    self.totalDisdance.text = [NSString stringWithFormat:@"%.2f", self.track.totalDistance];
    int time = (int) self.track.totalTime;
    self.totalTime.text = [NSString stringWithFormat:@"%02d:%02d:%02d", time / 3600, (time % 3600) / 60, time % 60];
}

- (void)setupMapView{
    
    //使用XIB时,在ViewDidLoad中的视图尺寸和XIB中预览的尺寸一致(视图的尺寸还没有同步设备的真实尺寸)
    
    //创建mapVc
    LXJMapViewController *mapVc = [[LXJMapViewController alloc] init];
    //使用父子控制器的方式
    //1.添加视图控制器(不添加也可以显示,但是响应者链条断开)    SB添加视图控制器使用ContainerView
    [self addChildViewController:mapVc];
    //2.添加内容视图为子视图
    [self.view insertSubview:mapVc.view atIndex:0];
    //3.设置子视图的尺寸 添加子视图时一定要设置其尺寸,避免出现autoresizing的错误处理
    mapVc.view.frame = self.view.bounds;
    //官方推荐
    [mapVc didMoveToParentViewController:self];
    self.mapVc = mapVc;
}
- (void)setTrack:(LXJSportTrack *)track{
    
    _track = track;
    //传递轨迹模型
    self.mapVc.track = track;
}

- (IBAction)closeMapAction:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)switchMapModeAction:(UIButton *)sender {
}

@end
